package com.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dao.QuestionDao;
import com.dao.ZixunDao;
import com.pojo.Question;
import com.pojo.Zixun;
import com.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class WendaService extends ServiceImpl<QuestionDao, Question> {

    @Autowired
    private  QuestionDao questionDao;
    public IPage getZixunPage(int page, int limit, String question, Integer status) {
        Page p=new Page(page,limit);
        QueryWrapper<Question> qw=new QueryWrapper<>();
        if (StringUtil.isNotNull(question)){
            qw.like("question",question);
        }
        if(status != null && status != -1) {
            qw.eq("status" , status) ;
        }
        IPage iPage=questionDao.selectPage(p,qw);
        return iPage;
    }

    public IPage selectpage(Integer page, Integer limit, String keywords) {
        Page p=new Page(page,limit);
        QueryWrapper<Question> qw=new QueryWrapper<>();
        if (StringUtil.isNotNull(keywords)){
            qw.like("question",keywords);

        }
        qw.eq("status",1);
        IPage iPage=questionDao.selectPage(p,qw);
        return iPage;
    }
}
